<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Progressive Play Server
 * Search Controller
 * /controllers/search.php
 * By: Yukwunhang
 */
class Search extends MY_Controller
{
	// Constructor
	function Search()
	{
		parent::MY_Controller();
		// Load model
		$this->load->model('player_model', 'player');
	}
	
	/**
	 * Get, process, return search result.
	 * @return 
	 */
	function index()
	{
		// Set up
		$keyword = $this->input->post('search');
		$keyword = $this->input->xss_clean($keyword); // XSS filtering
		$keyword = trim($keyword); // Remove whitespace from the beginning and the end of the string
		$limit = 40; // Limit result
		
		// Perform search
		$this->data['player'] = $this->player->search_player_by_name($keyword, $limit);
		
		// Extract total rows and move it one level higher in the array
		$this->data['num_rows'] = $this->data['player']['num_rows'];
		unset($this->data['player']['num_rows']);
		
		// Also pass the keyword searched... and the limit.
		$this->data['keyword'] = $keyword;
		$this->data['limit'] = $limit;

		// Load view into template, render.
		$this->template->write('title', 'Searching for: '.$keyword.' | Progressive Play Server');
		$this->template->write_view('content', 'player/search_player_view', $this->data);
		$this->template->render();
	}
}